package practico.entidades;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;


@Entity
@Table(name="ped")
public class Pedido {

	public Pedido() {
		// TODO Auto-generated constructor stub
	}
	@Id
	@Column(name="ped_id")
    @SequenceGenerator(name = "seq_ped", sequenceName = "seq_ped", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_ped")

	private int id;
	@Column(name="ped_dsc")
	private String descripcion;
	@Column(name="ped_pso")
	private double peso;
	@Column(name="ped_vol")
	private double volumen;
	@Column(name="ped_dir_org")
	private String origen;
	@Column(name="ped_dir_dst")
	private String destino;
	
	@ManyToOne
	@JoinColumn(name="ped_cli_id")
	private Cliente cliente;
	@ManyToOne
	@JoinColumn(name="ped_tra_id")
	private Transportista transportista;
	@ManyToOne
	@JoinColumn(name="ped_adm_id")
	private Administrador administrador;

    @OneToMany(mappedBy="pedido",fetch = FetchType.EAGER)
    @Cascade({CascadeType.SAVE_UPDATE})
	private List<HistorialPedido> historial;

	public Pedido(int id, String descripcion, double peso, double volumen,
			String origen, String destino, List<HistorialPedido> historial) {
		super();
		this.id = id;
		this.descripcion = descripcion;
		this.peso = peso;
		this.volumen = volumen;
		this.origen = origen;
		this.destino = destino;
		this.historial = historial;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public double getPeso() {
		return peso;
	}

	public void setPeso(double peso) {
		this.peso = peso;
	}

	public double getVolumen() {
		return volumen;
	}

	public void setVolumen(double volumen) {
		this.volumen = volumen;
	}

	public String getOrigen() {
		return origen;
	}

	public void setOrigen(String origen) {
		this.origen = origen;
	}

	public String getDestino() {
		return destino;
	}

	public void setDestino(String destino) {
		this.destino = destino;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public Transportista getTransportista() {
		return transportista;
	}

	public void setTransportista(Transportista transportista) {
		this.transportista = transportista;
	}

	public Administrador getAdministrador() {
		return administrador;
	}

	public void setAdministrador(Administrador administrador) {
		this.administrador = administrador;
	}

	public List<HistorialPedido> getHistorial() {
		return historial;
	}

	public void setHistorial(List<HistorialPedido> historial) {
		this.historial = historial;
	}
	
	public void addHistorial(HistorialPedido h){
		this.historial.add(h);
	}
    
}
